﻿namespace Nello.Web.Controls
{
    using Nello;
    using Nello.Web;
    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    [ToolboxData("<{0}:NTextBox runat=\"server\" />")]
    public class NTextBox : TextBox, IDataControl
    {
        private Nello.DataType datatype = Nello.DataType.String;
        private bool isignore = false;
        private bool isRequired = false;

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
            if (this.isRequired)
            {
                writer.Write("<a onclick='javascript:document.all." + this.ClientID + ".focus();' title='该选项为必填项' style='cursor:hand'><font color='red'>*</font></a>");
            }
        }

        public Nello.DataType DataType
        {
            get
            {
                return this.datatype;
            }
            set
            {
                this.datatype = value;
            }
        }

        [Browsable(false)]
        public object DataValue
        {
            get
            {
                return DataTypeUtil.GetValue(this.datatype, this.Text);
            }
            set
            {
                if (value == null)
                {
                    this.Text = "";
                }
                else
                {
                    this.Text = value.ToString();
                }
            }
        }

        public bool IsIgnore
        {
            get
            {
                return this.isignore;
            }
            set
            {
                this.isignore = value;
            }
        }

        public bool IsRequired
        {
            get
            {
                return this.isRequired;
            }
            set
            {
                this.isRequired = value;
            }
        }
    }
}

